package com.fesine.util;

import org.apache.log4j.Logger;
import org.apache.shiro.codec.Base64;
import org.apache.shiro.crypto.hash.Md5Hash;

/**
 * Created by Fesine on 2016/6/19.
 */
public class CryptographyUtil {

    private static final Logger logger = Logger.getLogger(CryptographyUtil.class);

    /**
     * 基于base64进行加密，对称，可进行解密
     * @param string
     * @return
     */
    public static String encBase64(String string) {
        return Base64.encodeToString(string.getBytes());
    }

    /**
     * base64解密
     * @param string
     * @return
     */
    public static String decBase64(String string) {
        return Base64.decodeToString(string);
    }

    /**
     * md5加密
     * @param str
     * @param salt
     * @return
     */
    public static String md5(String str, String salt) {
        return new Md5Hash(str,salt).toString();
    }

    public static void main(String[] args) {
        String password = "123";
        logger.info("base64加密："+CryptographyUtil.encBase64(password));
        logger.info("base64解密密："+CryptographyUtil.decBase64(CryptographyUtil.encBase64(password)));
        logger.info("md5加密："+CryptographyUtil.md5(password,"fesine"));
    }
}
